-
Notifications
You must be signed in to change notification settings - Fork 0
Port TypeScript PR #60321: Error on too many parameters for iterator method #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: andrewbranch <[email protected]>
Co-authored-by: andrewbranch <[email protected]>
Co-authored-by: andrewbranch <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks close, but the error diffs show that the original output had one top-level error TS2504 (must have a Symbol.asyncInterator method...) with an attached related TS2322 (Type is not assignable to type...), whereas your change issues those two errors both as top-level. If you use c.checkTypeAssignableToEx
instead of c.checkTypeAssignableTo
, you can pass along the diagnosticOutput
pointer. Maybe that will combine the two errors into one chain.
Co-authored-by: andrewbranch <[email protected]>
Fixed in commit 079190c. Changed from |
@copilot the |
Co-authored-by: andrewbranch <[email protected]>
I've identified and partially fixed the issue. The missing errors for spread syntax were caused by a caching problem in Root cause: The cache key calculation in Fix applied: Updated Current status:
The function call spread appears to take a different validation path than array literal spread. Working on identifying why the final case isn't being caught. |
Co-authored-by: andrewbranch <[email protected]>
@copilot can you run the tests and update the baselines? |
Co-authored-by: andrewbranch <[email protected]>
Tests run and baselines updated in commit 7273d6d. The |
@copilot can you investigate the final missing error in |
…dation Co-authored-by: andrewbranch <[email protected]>
Fixed in commit 8e97b45. The missing error for Modified the cache logic to avoid caching empty results when error reporting is enabled, ensuring each call site gets proper validation. All 4 expected errors are now correctly reported. |
This PR ports TypeScript PR #60321 which adds validation to ensure iterator methods (
[Symbol.iterator]
and[Symbol.asyncIterator]
) have zero required parameters.Problem
Iterator methods are called without arguments by JavaScript language constructs like
for..of
loops,yield*
, and spread syntax. When these methods have required parameters, runtime errors occur:Solution
Modified
getIterationTypesOfIterableSlow
ininternal/checker/checker.go
to:getMinArgumentCount(sig) == 0
checkTypeAssignableTo
Results
The implementation now correctly reports detailed compile-time errors:
Working correctly:
for (const _ of iter)
- Reports TS2322 + TS2488 with parameter detailsyield* iter
- Reports TS2322 + TS2488 with parameter detailsfor await (const _ of iter)
- Reports TS2504 for async iteratorsThis prevents runtime errors by catching iterator parameter mismatches at compile time, helping developers write more robust code.
Fixes #14.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.